<template>
  <div id="PickDetail">
    <v-details
      :inputConfig="inputConfig"
      :detailData="inputData"
      :rules="rules"
      @pop="setdata"
      ref="input"
    ></v-details>
  </div>
</template>

<script>
import details from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  props: {
    inputData: {
      type: Object,
    },
  },
  mixins: [baseMixin],
  name: "PickDetail",
  data() {
    //自定义验证规则,验证LPN是否合法
    const qtyValidate = (rule, value, callback) => {
      let reg = /^\+?[1-9]\d*$/; //大于零的正整数
      if (!reg.test(value)) {
        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
        this.inputData.qty = this.qty;
        callback(new Error());
      } else {
        callback();
        //}
      }
    };
    return {
      qty: 0,
      inputConfig: [
        [
          {
            type: "input",
            label: this.$t("out.orderkey"),
            disabled: true,
            props: "orderkey",
          },
          {
            type: "input",
            label: this.$t("outbound.userlinenumber"),
            disabled: true,
            props: "orderlinenumber",
          },
          {
            type: "input",
            label: this.$t("config.sku"),
            disabled: true,
            props: "sku",
          },
          {
            type: "select",
            label: this.$t("common.status"),
            props: "status",
            options: this.getOptions("querycodeLkup/ORDRSTATUS"),
          },
          {
            type: "input",
            label: this.$t("out.statusrequired"),
            props: "statusrequired",
          },
        ],
        [
          {
            type: "input",
            label: this.$t("config.shipper"),
            disabled: true,
            props: "storerkey",
          },
          {
            type: "input",
            label: this.$t("out.pickdetailkey"),
            disabled: true,
            props: "pickdetailkey",
          },
          {
            type: "input",
            label: this.$t("out.batchcartonid"),
            props: "batchcartonid",
          },
          {
            type: "date",
            label: this.$t("in.effectivedate"),
            props: "effectivedate",
          },
        ],
        [
          {
            type: "input",
            label: this.$t("config.packaging"),
            disabled: true,
            props: "packkey",
          },
          {
            type: "input",
            label: this.$t("config.measureUnit"),
            disabled: true,
            props: "uom",
          },
          {
            type: "input",
            label: this.$t("config.num"),
            props: "qty",
            disabled: true,
          },
          {
            type: "input",
            label: this.$t("out.uomqty"),
            props: "uomqty",
            disabled: true,
          },
          {
            type: "input",
            label: this.$t("config.gross"),
            props: "grosswgt",
          },
        ],
        [
          {
            type: "input",
            label: this.$t("in.lot"),
            props: "lot",
            disabled: true,
          },
          {
            type: "input",
            label: this.$t("in.lpn"),
            disabled: true,
            props: "id",
          },
          {
            type: "input",
            label: this.$t("config.toLoc"),
            props: "toloc",
            disabled: true,
          },
          {
            type: "input",
            label: this.$t("config.loc"),
            props: "loc",
            disabled: true,
          },
          {
            type: "input",
            label: this.$t("config.suttle"),
            props: "netwgt",
          },
        ],
        [
          {
            type: "select",
            label: this.$t("out.isclosed"),
            props: "isclosed",
            options: this.getOptions("querycodeLkup/YESNO"),
          },
          {
            type: "select",
            label: this.$t("in.qcstatus"),
            props: "qcstatus",
            options: this.getOptions("querycodeLkup/QCSTATUS"),
          },
          {
            type: "input",
            label: this.$t("out.trackingid"),
            props: "trackingid",
          },
          {
            type: "input",
            label: this.$t("in.asnCode"),
            disabled: true,
            props: "receiptkey",
          },
          {
            type: "input",
            label: this.$t("config.tareWeight"),
            props: "tarewgt",
          },
        ],
      ],
      rules: {
        qty: [{ required: true, trigger: "blur", validator: qtyValidate }],
        grosswgt: [{ trigger: "blur", validator: this.verify }],
        netwgt: [{ trigger: "blur", validator: this.verify }],
        tarewgt: [{ trigger: "blur", validator: this.verify }],
      },
    };
  },
  computed: {},
  methods: {
    verify(rule, value, callback) {
      if (value === "") {
        this.inputData[rule.field] = 0;
        callback(new Error());
      } else {
        var re = /[^0-9.]/;
        let te = value;
        let flag = re.test(te);
        if (!flag) {
          if (value < 0) {
            this.$message.error(this.$t("app.inputNumberPlease"));
            this.inputData[rule.field] = 0;
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t("app.inputNumberPlease"));
          this.inputData[rule.field] = 0;
          callback(new Error());
        }
      }
    },
    setdata(data, id, close, listId) {},
  },
  mounted() {
    this.qty = this.inputData.qty;
    /*if (!(this.inputData.status === '1' || this.inputData.status === '5')) {
            this.inputConfig[2][2].disabled = false
        }*/
    if (this.inputData.status === "0") {
      this.inputConfig[2][2].disabled = false;
    }
  },
  watch: {
    inputData: {
      handler(newValue, oldValue) {
        if (newValue.status === "0") {
          this.inputConfig[2][2].disabled = false;
        } else {
          this.inputConfig[2][2].disabled = true;
        }
      },
      deep: true,
    },
  },
  components: {
    "v-details": details,
  },
};
</script>

<style scoped></style>
